function  [eta, hat_kappa0, lvg, kappap_multiplier] = adjust_eta_and_kappa0( model_sol_raw,  bank_leverage_target , loss_given_default )
% Usage: adjust the eta for all the solution files of Smolayak grid.

eta_lower = 0.001;  eta_upper = 0.3;  improvement = 1;  N_years=2000;  
% -model_sol_raw.par.eta+0.001
% if( strcmp(model_sol_raw.par.model_name,'benchmark') )
%     eta_upper=20;
% end
diff = 10;    iter_count_max=10;   iter=0;
model_sol_iter = post_processing(model_sol_raw);
while( abs(diff) > 0.01 && iter <iter_count_max && improvement>0.02 )
    par = model_sol_iter.par;   
    par.supress_credit_spread_in_simulation = true;   % Important: we do not need to solve creidt spread in this loop
    w_init=0.15;  lambda_init= (par.lambda_H + par.lambda_L)/2;  random_seed=1;
    shocks = shocks_generation( N_years,  par, random_seed);  

    eta_new = max((eta_lower+eta_upper)/2,0);
    model_sol_iter = post_processing_change_eta(model_sol_iter, eta_new);  
    sim = simulate( w_init, lambda_init,  shocks.dB_vec, shocks.dN_vec,  N_years, model_sol_iter,  par  );
    
    if( par.model_name == "behavioral" )    
        sim_results = sim.behavioral;
    else
        sim_results = sim.rational;
    end
    improvement = (diff -  ( mean(sim_results.xK) - bank_leverage_target ) / bank_leverage_target) / diff;
    diff = ( mean(sim_results.xK) - bank_leverage_target ) / bank_leverage_target;
    if(abs(diff) < 0.01)
        break;
    end
    if( diff>0 )
        eta_upper = model_sol_iter.par.eta;
    else
        eta_lower =  model_sol_iter.par.eta;
    end
          
    disp( [ 'round ', num2str(iter), ' leverage=', num2str(mean(sim_results.xK))] )
    iter = iter+1;
end
eta = model_sol_iter.par.eta;  
moments = simulation_moments( sim, model_sol_iter );
crises_index = moments.crises_starting_index_vec(moments.crises_starting_index_vec>10);
kappap_sim =  (  moments.p( crises_index-1 ) - moments.p(crises_index+1 )  )  ./ moments.p( crises_index-1 ) ;

kappap_multiplier = 0.1 / mean(kappap_sim);  % the multiplier over kappap should generate additional 10% of losses in GDP.
hat_kappa0 = loss_given_default - 0.1 * par.crisis_frequency_target;  % the fixed component. 
lvg = mean(sim_results.xK);
